package com.wgc.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wgc.vip.domain.Evaluation;
import com.wgc.vip.domain.Vip;
import com.wgc.vip.service.EvaluationService;
import com.wgc.vip.mapper.EvaluationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 15776
* @description 针对表【evaluation】的数据库操作Service实现
* @createDate 2024-07-29 21:26:18
*/
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, Evaluation>
    implements EvaluationService{
@Autowired
    private EvaluationMapper evaluationMapper;
    @Override
    public List<Evaluation> getAll() {
        LambdaQueryWrapper<Evaluation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Evaluation::getIsDelete, 0);
        return evaluationMapper.selectList(queryWrapper);
    }

    @Override
    public Integer insert(Evaluation e) {
        return evaluationMapper.insert(e);
    }

    @Override
    public Integer delete(String ids) {
        try {
            String[] idArr = ids.split(",");
            for (String id : idArr) {
                Evaluation e = new Evaluation();
                e.setId(Long.parseLong(id));
                e.setIsDelete(1);
                evaluationMapper.updateById(e);
            }
            return 1;
        } catch (Exception e) {
            return -1;
        }
    }

    @Override
    public Integer status(Long id, Integer status) {
        LambdaQueryWrapper<Evaluation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Evaluation::getId, id);
        Evaluation e = evaluationMapper.selectOne(lqw);
        e.setStatus(status);
        return evaluationMapper.updateById(e);
    }

    @Override
    public List<Evaluation> getByName(String name) {
        LambdaQueryWrapper<Evaluation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Evaluation::getIsDelete, 0);
        lqw.like(Evaluation::getVipName, name);
        return evaluationMapper.selectList(lqw);
    }

    @Override
    public Page<Evaluation> pageList(Evaluation e, Integer page, Integer size) {
        LambdaQueryWrapper<Evaluation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Evaluation::getIsDelete, 0);
        lqw.like(Evaluation::getVipName, e.getVipName());
        Page<Evaluation> page1 = new Page<>(page, size);
        return this.page(page1, lqw);
    }

    @Override
    public Page<Evaluation> pageAll(Integer page, Integer size) {
        LambdaQueryWrapper<Evaluation> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Evaluation::getIsDelete, 0);
        Page<Evaluation> page1 = new Page<>(page, size);
        return this.page(page1, lqw);
    }

}




